<template>
<div class="cms_comment">
 
<div class="btns">
    <el-form size="small" inline style="text-align:center">
          <el-form-item label="关键字">
               <el-input v-model="param.content"></el-input>
          </el-form-item>
          <el-form-item>
              <el-button size="small" type="primary" icon="el-icon-search" @click="loadComment">搜索</el-button>
          </el-form-item>
    </el-form>
     
<div style="text-align:right">
    <el-button size="small" type="primary" round @click="downloadHandler">导出</el-button>
    <el-button size="small" type="primary" round @click="toAddHandler" >新增</el-button>
</div>
</div>
<el-alert
    center
    title="评论模块"
    type="info"
    effect="dark                                                                                                                                                                                                                               ">
  </el-alert>


<el-table  style="width: 100%" size="small" :data="comment">
      <el-table-column type="index" label="序号"> </el-table-column>
      <el-table-column prop="content" label="评论内容" width="180"> </el-table-column>
      <el-table-column prop="commentTime" label="评论时间"> </el-table-column>
      <el-table-column  type="index" prop="floor" label="评论楼层"></el-table-column>
      <el-table-column prop="status" label="评论状态"> </el-table-column>
      <el-table-column prop="userId" label="用户ID"> </el-table-column>
      <el-table-column prop="articleId" label="文章ID"> </el-table-column>
      <el-table-column prop="parentId" label="父类ID"> </el-table-column>
      <el-table-column label="操作" width="200" align="center">
          <template slot-scope="scope">
              <el-button type="primary" round icon="el-icon-edit" size="mini" @click="editHandler(scope.row)">修改</el-button>
              <el-button type="danger" round icon="el-icon-delete" size="mini" @click="deleteHandler(scope.row)">删除</el-button>
          </template>
      </el-table-column>
</el-table>
</div>
</template>

<script>
import {get,post, del} from '@/utils/request'
export default {
    data(){
        return{
            param:{},
            comment:[]
        }
    },
//部件
created() {
     this.loadComment();
},
methods:{
     downloadHandler(){
         if(this.param.content){
      window.location.href = "http://39.106.31.187:8888/comment/download?content="+this.param.content;
      }else {
        window.location.href = "http://39.106.31.187:8888/comment/download"
      }
      
    },
    editHandler(row) {
        this.$router.push({
            path:"/article/commentCreate",
            query:row
        })      
    },
    deleteHandler(row) {
        this.$confirm("此操作将永久删除此数据，是否继续？","提示",{
            confirmButtonText:"确定",
            cancelButtonText:"取消",
            type:"warning",
        }).then(()=>{
            let url = "http://39.106.31.187:8888/comment/deleteById";
            del(url, {id:row.id}).then((resp)=>{
                this.$message({type:"success",message:resp.message});
                this.loadComment();
            });
        });
    },
    toAddHandler(){
        this.$router.push("/article/commentCreate")
    },
    loadComment(){
        let url ='http://39.106.31.187:8888/comment/query'
        get(url,this.param).then((resp)=>{
            this.comment=resp.data;
        });
    },
  },
}
</script>

<style scoped>
.btns{
    margin-bottom: .5em;
}
</style>